package com.inbox.action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.smartstruts.action.Action;
import org.smartstruts.action.ActionForm;

import com.inbox.domain.Message;
import com.inbox.form.InboxForm;
import com.inbox.service.InboxService;

/**
 * 显示信息处理类
 * 
 * @author Wangpeihu
 * @since 08/01/2010
 * @version 1.0
 * 
 */
public class InboxAction extends Action {

	/** 每页显示的行数 */
	private static final int ROWS_PER_PAGE = 5;

	@Override
	public String execute(ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {

		/** 得到用户提交的页面的表单信息,该对象封装了用户想要查看的页码值 */
		InboxForm inboxForm = (InboxForm) form;
		InboxService is = new InboxService();

		/** 得到消息列表 */
		List<Message> msgList = is.findAllMessage(ROWS_PER_PAGE, inboxForm
				.getPage(), inboxForm.getOrder());

		/** 获得一共需要显示多少页 */
		int totalPages = is.getMessageTotalPages(ROWS_PER_PAGE);

		Map<Integer, String> orderOptions = is.getMessageOrderOptions();

		request.setAttribute("orderOptions", orderOptions);
		request.setAttribute("totalPages", totalPages);
		request.setAttribute("msgList", msgList);
		return "success";
	}
}
